package com.example.experiment2;

import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SecondActivity extends AppCompatActivity {
    private ListView listView;
    List<Map<String,Object>> toMap(Bundle bundle){
        String schoolNumber=bundle.getString("schoolNumber");
        String name=bundle.getString("name");
        String sex=bundle.getString("sex");
        String collage=bundle.getString("collage");
        String major=bundle.getString("major");
        String schoolClass=bundle.getString("schoolClass");

        List<Map<String,Object>> mapList=new ArrayList<>();

        Map<String,Object> schoolNumberMap=new HashMap<>();
        schoolNumberMap.put("img",R.drawable.credit_card_black);
        schoolNumberMap.put("value",schoolNumber);

        Map<String,Object> nameMap=new HashMap<>();
        nameMap.put("img",R.drawable.account_box_black);
        nameMap.put("value",name);

        Map<String,Object> sexMap=new HashMap<>();
        sexMap.put("img",R.drawable.wc_black);
        sexMap.put("value",sex);

        Map<String,Object> collageMap=new HashMap<>();
        collageMap.put("img",R.drawable.account_balance_black);
        collageMap.put("value",collage);

        Map<String,Object> majorMap=new HashMap<>();
        majorMap.put("img",R.drawable.school_black);
        majorMap.put("value",major);

        Map<String,Object> schoolClassMap=new HashMap<>();
        schoolClassMap.put("img",R.drawable.assignment_ind_black);
        schoolClassMap.put("value",schoolClass);

        mapList.add(schoolNumberMap);
        mapList.add(nameMap);
        mapList.add(sexMap);
        mapList.add(collageMap);
        mapList.add(majorMap);
        mapList.add(schoolClassMap);

        return mapList;
    }
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        listView=findViewById(R.id.listview);

        Bundle bundle=getIntent().getExtras();

        String[] from={"img","value"};
        int[] to = { R.id.item_img, R.id.item_text };
        SimpleAdapter simpleAdapter=new SimpleAdapter(this,toMap(bundle),R.layout.item_layout,from,to);
        listView.setAdapter(simpleAdapter);
    }
}
